package com.mine.result;



public class Result{
	
	// 响应业务状态
	private int code;
	// 响应消息
	private String msg;
	// 响应中的数据
	private Object data;
	
	/**
	 *  成功时候的调用
	 * */
	public static  Result success(Object data){
		return new Result(data);
	}
	public static  Result ok(){
		return new Result(200,"success");
	}
	/**
	 *  失败时候的调用 CodeMsg
	 * */
	public static  Result error(CodeMsg codeMsg){
		return new Result(codeMsg);
	}
	
	/**
	 *  失败时候的调用 不用CodeMsg 自己构造Result
	 * */
	public static  Result error(int code,String msg){
		return new Result(code, msg);
	}
	/**
	 *  失败时候的调用 不用CodeMsg 自己用String构造Result
	 * */
	public static  Result error(String msg){
		return new Result(500, msg);
	}
	
	private Result(Object data) {
		this.msg ="ok";
		this.code =200;
		this.data = data;
	}
	
	private Result(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
	private Result(CodeMsg codeMsg) {
		if(codeMsg != null) {
			this.code = codeMsg.getCode();
			this.msg = codeMsg.getMsg();
		}
	}
	
	
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
}
